Bokeh Tutorial

1.3 Plotting - Worldmap

Exercise: Draw a worldmap with the plotting interface

Note: For your convienience, I've written a script world_countries.py that parses the XML of country polygons from the dataset: World_Country_Boundaries.csv.gz


In [ ]:
# Get data
import utils.world_countries as wc
world_countries = wc.data.copy()

In [ ]:
import pandas as pd
from bokeh.plotting import figure, show, output_notebook

In [ ]:
# Process data
worldmap = pd.DataFrame.from_dict(world_countries, orient='index')

In [ ]:
# Output option
output_notebook()

In [ ]:
# Create your plot
p = figure(plot_height=500, plot_width=900, toolbar_location="left",
    x_axis_type=None, y_axis_type=None)

p.patches(xs=worldmap['lons'], ys=worldmap['lats'], fill_color="white", fill_alpha=0,
    line_color="black", line_width=0.5)

In [ ]:
# Show plot
show(p)